r"""
Run this script using the server32 executable to see which modules from
the standard library cannot be imported, e.g.,

  server32-windows.exe -m ..\..\tests\check_server32_imports

The following error will be displayed when the script exits (but that's ok)

  AttributeError: module check_server32_imports.py
  Module does not contain a class that is a subclass of Server32.
  Cannot start the 32-bit server.

"""
import importlib

# Builtin modules in Python 3.12 (https://docs.python.org/3/py-modindex.html)
# (module-name, operating-system-dependency)
modules = [
    ('__future__', ''),
    ('__main__', ''),
    ('_thread', ''),
    ('abc', ''),
    ('aifc', ''),
    ('argparse', ''),
    ('array', ''),
    ('ast', ''),
    ('asyncio', ''),
    ('atexit', ''),
    ('audioop', ''),
    ('base64', ''),
    ('bdb', ''),
    ('binascii', ''),
    ('bisect', ''),
    ('builtins', ''),
    ('bz2', ''),
    ('calendar', ''),
    ('cgi', ''),
    ('cgitb', ''),
    ('chunk', ''),
    ('cmath', ''),
    ('cmd', ''),
    ('code', ''),
    ('codecs', ''),
    ('codeop', ''),
    ('collections', ''),
    ('collections.abc', ''),
    ('colorsys', ''),
    ('compileall', ''),
    ('concurrent', ''),
    ('concurrent.futures', ''),
    ('configparser', ''),
    ('contextlib', ''),
    ('contextvars', ''),
    ('copy', ''),
    ('copyreg', ''),
    ('cProfile', ''),
    ('crypt', '(Unix)'),
    ('csv', ''),
    ('ctypes', ''),
    ('curses', '(Unix)'),
    ('curses.ascii', '(Unix)'),
    ('curses.panel', '(Unix)'),
    ('curses.textpad', '(Unix)'),
    ('dataclasses', ''),
    ('datetime', ''),
    ('dbm', ''),
    ('dbm.dumb', ''),
    ('dbm.gnu', '(Unix)'),
    ('dbm.ndbm', '(Unix)'),
    ('decimal', ''),
    ('difflib', ''),
    ('dis', ''),
    ('doctest', ''),
    ('email', ''),
    ('email.charset', ''),
    ('email.contentmanager', ''),
    ('email.encoders', ''),
    ('email.errors', ''),
    ('email.generator', ''),
    ('email.header', ''),
    ('email.headerregistry', ''),
    ('email.iterators', ''),
    ('email.message', ''),
    ('email.mime', ''),
    ('email.mime.application', ''),
    ('email.mime.audio', ''),
    ('email.mime.base', ''),
    ('email.mime.image', ''),
    ('email.mime.message', ''),
    ('email.mime.multipart', ''),
    ('email.mime.nonmultipart', ''),
    ('email.mime.text', ''),
    ('email.parser', ''),
    ('email.policy', ''),
    ('email.utils', ''),
    ('encodings', ''),
    ('encodings.idna', ''),
    ('encodings.mbcs', ''),
    ('encodings.utf_8_sig', ''),
    ('ensurepip', ''),
    ('enum', ''),
    ('errno', ''),
    ('faulthandler', ''),
    ('fcntl', '(Unix)'),
    ('filecmp', ''),
    ('fileinput', ''),
    ('fnmatch', ''),
    ('fractions', ''),
    ('ftplib', ''),
    ('functools', ''),
    ('gc', ''),
    ('getopt', ''),
    ('getpass', ''),
    ('gettext', ''),
    ('glob', ''),
    ('graphlib', ''),
    ('grp', '(Unix)'),
    ('gzip', ''),
    ('hashlib', ''),
    ('heapq', ''),
    ('hmac', ''),
    ('html', ''),
    ('html.entities', ''),
    ('html.parser', ''),
    ('http', ''),
    ('http.client', ''),
    ('http.cookiejar', ''),
    ('http.cookies', ''),
    ('http.server', ''),
    ('idlelib', ''),
    ('imaplib', ''),
    ('imghdr', ''),
    ('importlib', ''),
    ('importlib.abc', ''),
    ('importlib.machinery', ''),
    ('importlib.metadata', ''),
    ('importlib.resources', ''),
    ('importlib.resources.abc', ''),
    ('importlib.util', ''),
    ('inspect', ''),
    ('io', ''),
    ('ipaddress', ''),
    ('itertools', ''),
    ('json', ''),
    ('json.tool', ''),
    ('keyword', ''),
    ('lib2to3', ''),
    ('linecache', ''),
    ('locale', ''),
    ('logging', ''),
    ('logging.config', ''),
    ('logging.handlers', ''),
    ('lzma', ''),
    ('mailbox', ''),
    ('mailcap', ''),
    ('marshal', ''),
    ('math', ''),
    ('mimetypes', ''),
    ('mmap', ''),
    ('modulefinder', ''),
    ('msilib', '(Windows)'),
    ('msvcrt', '(Windows)'),
    ('multiprocessing', ''),
    ('multiprocessing.connection', ''),
    ('multiprocessing.dummy', ''),
    ('multiprocessing.managers', ''),
    ('multiprocessing.pool', ''),
    ('multiprocessing.shared_memory', ''),
    ('multiprocessing.sharedctypes', ''),
    ('netrc', ''),
    ('nis', '(Unix)'),
    ('nntplib', ''),
    ('numbers', ''),
    ('operator', ''),
    ('optparse', ''),
    ('os', ''),
    ('os.path', ''),
    ('ossaudiodev', '(Linux, FreeBSD)'),
    ('pathlib', ''),
    ('pdb', ''),
    ('pickle', ''),
    ('pickletools', ''),
    ('pipes', '(Unix)'),
    ('pkgutil', ''),
    ('platform', ''),
    ('plistlib', ''),
    ('poplib', ''),
    ('posix', '(Unix)'),
    ('pprint', ''),
    ('profile', ''),
    ('pstats', ''),
    ('pty', '(Unix)'),
    ('pwd', '(Unix)'),
    ('py_compile', ''),
    ('pyclbr', ''),
    ('pydoc', ''),
    ('queue', ''),
    ('quopri', ''),
    ('random', ''),
    ('re', ''),
    ('readline', '(Unix)'),
    ('reprlib', ''),
    ('resource', '(Unix)'),
    ('rlcompleter', ''),
    ('runpy', ''),
    ('sched', ''),
    ('secrets', ''),
    ('select', ''),
    ('selectors', ''),
    ('shelve', ''),
    ('shlex', ''),
    ('shutil', ''),
    ('signal', ''),
    ('site', ''),
    ('smtplib', ''),
    ('sndhdr', ''),
    ('socket', ''),
    ('socketserver', ''),
    ('spwd', '(Unix)'),
    ('sqlite3', ''),
    ('ssl', ''),
    ('stat', ''),
    ('statistics', ''),
    ('string', ''),
    ('stringprep', ''),
    ('struct', ''),
    ('subprocess', ''),
    ('sunau', ''),
    ('symtable', ''),
    ('sys', ''),
    ('sysconfig', ''),
    ('syslog', '(Unix)'),
    ('tabnanny', ''),
    ('tarfile', ''),
    ('telnetlib', ''),
    ('tempfile', ''),
    ('termios', '(Unix)'),
    ('test', ''),
    ('test.regrtest', ''),
    ('test.support', ''),
    ('test.support.bytecode_helper', ''),
    ('test.support.import_helper', ''),
    ('test.support.os_helper', ''),
    ('test.support.script_helper', ''),
    ('test.support.socket_helper', ''),
    ('test.support.threading_helper', ''),
    ('test.support.warnings_helper', ''),
    ('textwrap', ''),
    ('threading', ''),
    ('time', ''),
    ('timeit', ''),
    ('tkinter', ''),
    ('tkinter.colorchooser', ''),
    ('tkinter.commondialog', ''),
    ('tkinter.dnd', ''),
    ('tkinter.filedialog', ''),
    ('tkinter.font', ''),
    ('tkinter.messagebox', ''),
    ('tkinter.scrolledtext', ''),
    ('tkinter.simpledialog', ''),
    ('tkinter.tix', ''),
    ('tkinter.ttk', ''),
    ('token', ''),
    ('tokenize', ''),
    ('tomllib', ''),
    ('trace', ''),
    ('traceback', ''),
    ('tracemalloc', ''),
    ('tty', '(Unix)'),
    ('turtle', ''),
    ('turtledemo', ''),
    ('types', ''),
    ('typing', ''),
    ('unicodedata', ''),
    ('unittest', ''),
    ('unittest.mock', ''),
    ('urllib', ''),
    ('urllib.error', ''),
    ('urllib.parse', ''),
    ('urllib.request', ''),
    ('urllib.response', ''),
    ('urllib.robotparser', ''),
    ('uu', ''),
    ('uuid', ''),
    ('venv', ''),
    ('warnings', ''),
    ('wave', ''),
    ('weakref', ''),
    ('webbrowser', ''),
    ('winreg', '(Windows)'),
    ('winsound', '(Windows)'),
    ('wsgiref', ''),
    ('wsgiref.handlers', ''),
    ('wsgiref.headers', ''),
    ('wsgiref.simple_server', ''),
    ('wsgiref.types', ''),
    ('wsgiref.util', ''),
    ('wsgiref.validate', ''),
    ('xdrlib', ''),
    ('xml', ''),
    ('xml.dom', ''),
    ('xml.dom.minidom', ''),
    ('xml.dom.pulldom', ''),
    ('xml.etree.ElementInclude', ''),
    ('xml.etree.ElementTree', ''),
    ('xml.parsers.expat', ''),
    ('xml.parsers.expat.errors', ''),
    ('xml.parsers.expat.model', ''),
    ('xml.sax', ''),
    ('xml.sax.handler', ''),
    ('xml.sax.saxutils', ''),
    ('xml.sax.xmlreader', ''),
    ('xmlrpc', ''),
    ('xmlrpc.client', ''),
    ('xmlrpc.server', ''),
    ('zipapp', ''),
    ('zipfile', ''),
    ('zipimport', ''),
    ('zlib', ''),
    ('zoneinfo', '')
]

print('The following modules cannot be imported')

# these are mandatory
from msl import loadlib
from msl.loadlib import LoadLibrary
from msl.loadlib import Client64
from msl.loadlib import Server32
from msl.loadlib import constants
from msl.loadlib import utils
from msl.loadlib.activex import Application
from msl.loadlib.activex import Background
from msl.examples.loadlib import EXAMPLES_DIR

from sys import monitoring

if constants.IS_WINDOWS:
    import clr
    import comtypes
    import pythonnet

for name, os in modules:
    try:
        importlib.import_module(name)
    except ImportError:
        print(f'  {name} {os}')
print('')
